<?php

	$result = getAllergiesDataWS($pid);
	//$row = sqlFetchArray($result);
	$pCount =0;
	//while ($row = sqlFetchArray($result)) {
	
	//die (print_r($row));
	
	$e_Allergies = $ccr->createElement('Allergies');
	
	do {
		
		$pCount++;

		$e_Problem = $ccr->createElement('Allergy');
		$e_Allergies->appendChild($e_Problem);

		$e_CCRDataObjectID = $ccr->createElement('CCRDataObjectID', 'ALLER'.$pCount);
		$e_Problem->appendChild($e_CCRDataObjectID);

		$e_DateTime = $ccr->createElement('DateTime');
		$e_Problem->appendChild($e_DateTime);
		
		$date = date_create($row['date']);
		
		$e_ExactDateTime = $ccr->createElement('ExactDateTime', $date->format('Y-m-d\TH:i:s'));
		$e_DateTime->appendChild($e_ExactDateTime);
		
		$e_IDs = $ccr->createElement('IDs');
		$e_Problem->appendChild($e_IDs);
		
		$e_ID = $ccr->createElement('ID', $row['pid']);
		$e_IDs->appendChild($e_ID);

		$e_IDs->appendChild(sourceType($ccr, $sourceID));
		
		$e_Type = $ccr->createElement('Type');
		$e_Problem->appendChild($e_Type);
    
		$e_Text = $ccr->createElement('Text',$row['allergy_title']);
		$e_Type->appendChild($e_Text);

		$e_Begdate = $ccr->createElement('Begdate',$row['begdate'] );
		$e_Problem->appendChild($e_Begdate);
		
		$e_Enddate = $ccr->createElement('Enddate',$row['enddate'] );
		$e_Problem->appendChild($e_Enddate);
    
		/*$e_Text = $ccr->createElement('Text', 'Active');
		$e_Status->appendChild($e_Text);*/
		
		$e_CommentID = $ccr->createElement('CommentID', $row['comments']);
		$e_Problem->appendChild($e_CommentID);
		
		/*
		$e_Source = $ccr->createElement('Source');
		
		$e_Actor = $ccr->createElement('Actor');
		$e_Source->appendChild($e_Actor);
		
		$e_ActorID = $ccr->createElement('ActorID',$uuid);
		$e_Actor->appendChild($e_ActorID);
    
		$e_Problem->appendChild($e_Source);
    
		$e_CommentID = $ccr->createElement('CommentID', $row['comments']);
		$e_Problem->appendChild($e_CommentID);
		*/
		
	
	} while ($row = sqlFetchArray($result));
	//}

	// complex type should go in different find and should be included in createCCR.php
/*
	function sourceType($ccr, $uuid){
		
		$e_Source = $ccr->createElement('Source');
		
		$e_Actor = $ccr->createElement('Actor');
		$e_Source->appendChild($e_Actor);
		
		$e_ActorID = $ccr->createElement('ActorID',$uuid);
		$e_Actor->appendChild($e_ActorID);
		
		return $e_Source;
	}
*/
?>
